import { defineStore } from 'pinia'

const userStore = defineStore("wg_user", {
  state: () => {
    return {
      user: null
    }
  },
  actions: {
    updateUser(user) {
      this.user = user
    }
  },
  getters: {
    getUsername(state) {
      return state.user.name
    },
    getUserAvatar(state) {
      if(state.user && state.user.avatar) {
        return state.user.avatar + "?timestamp=" + new Date().getTime()
      }
      // 如果没有就显示一个默认的头像
      return "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg?" + new Date().getTime()
    },
    getUserPosition(state) {
      return state.user.position
    },
    getUserId(state) {
      return state.user.id
    },
    getUser(state) {
      return state.user
    }
  }
})

export default userStore